home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / 0938.ZIP / KEGELUNX.ARC / PROT.ASM < prev    next >
Assembly Source File  |  1985-06-10  |  2KB  |  116 lines

  1. page 66,132
  2. ;compressed mode on prn.
  3. page
  4.  
  5.  
  6. ;---- (un)prot.com ------------------------------------------------
  7. ; Usage: (un)prot filespec
  8. ; Write-protects (unprotects) filespec
  9. ; Wildcards allowed in filename 
  10. ; MCN  10 July 84
  11. ; DRK  29 July 84- to use new args, ffind; old DTA was getting clobbered?
  12. ;---------------------------------------------------------------
  13.     extrn    _args:near,argc:word,argv:word
  14.     extrn    ffirst:near,fnext:near,fnam:byte,finder:word
  15.  
  16. stderr    equ    2
  17.  
  18.  
  19. code    segment    public 'CODE'
  20. assume cs:code,ds:code,es:code
  21.  
  22. f_attrib    equ    21        ; offset from DTA of file attrib
  23.  
  24.     org    100h
  25.  
  26. ; This is a .COM program.
  27. ; It takes one argument- the name of a file (wildcards ok).
  28. ; The argument is the first nonblank string of chars.
  29. ; Either backslashes or forward slashes may be used in a pathname.
  30.  
  31. exist    proc    near
  32.  
  33.     ; Get arguments.
  34.     call    _args
  35.  
  36.     ; Check # of arguments- if not exactly one, send usage message.
  37.     cmp    argc,1
  38.     jnz    usage
  39.  
  40.     ; call DOS to see if file exists.
  41.     mov    dx, argv[2]    ; get pointer to first argument.
  42.     mov    cx, 0        ; no special attribute bits set
  43.     call    ffirst        ; FIND FIRST
  44.     jc    nofile        ; if carry set, no file found.
  45.  
  46. doit: 
  47.     mov    bx, finder
  48.     mov    cl, [bx][f_attrib]             
  49.     or    cl, 1        ; write protect
  50.     mov    ax, 4301h    ; put file mode
  51.     lea    dx, fnam    ; 
  52.     int    21h
  53.  
  54. next:    call    fnext        ; FIND NEXT
  55.     jnc    doit        ; again
  56.     mov    al, 0        ; errorlevel= 0 => file found
  57.     jmp    short exit
  58.  
  59. nlen    = 0
  60. nlen    = nend-noff
  61.  
  62. nofile:    mov    bx, stderr     ; error device
  63.     mov    cx,    nlen
  64.     mov    dx,    offset nmsg
  65.     mov    ah, 40h
  66.     int    21h
  67.     mov    al, 1        ; file not found error
  68.     jmp    short exit
  69.  
  70.     
  71.     
  72.  
  73. exit:    mov    ah, 4ch
  74.     int    21h        ; terminate process, return status in AL.
  75.  
  76. ulen    = 0
  77. ulen    =    uend-uoff
  78.  
  79. usage:    mov    bx, stderr    ; write to error device...
  80.     mov    cx, ulen
  81.     mov    dx, offset umsg
  82.     mov    ah, 40h
  83.     int    21h
  84.     mov    al, 2        ; error2 = syntax error
  85.     jmp    exit
  86.  
  87. nfw:
  88. blam:    mov    bx, stderr     ; error device
  89.     mov    cx,    nlen
  90.     mov    dx,    offset nmsg
  91.     mov    ah, 40h
  92.     int    21h
  93.     mov    al, 0ffh        ; file whiz error
  94.     jmp    exit
  95.  
  96. exist    endp
  97.  
  98.  
  99. handle    dw    ?
  100.     
  101. umsg    db    'Usage: prot filespec', 13, 10
  102. bugo    db    ?
  103. uoff    equ    offset umsg
  104. uend    equ    offset bugo
  105.  
  106. nmsg    db    'File not found', 13, 10
  107. nugo    db    ?
  108. noff    equ    offset nmsg
  109. nend    equ    offset nugo
  110.  
  111.  
  112. code    ends
  113.  
  114.     end    exist
  115.